# encoding: utf-8
"""
@author: LiuYusha
@file: yuce.py
@time: 2021/5/28 11:09
"""

# !/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2021/5/27 9:32
# @Author  : mxc
# @File    : yuce.py
# @Software: PyCharm
# !/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2021/5/27 9:32
# @Author  : mxc
# @File    : yuce.py
# @Software: PyCharm
import csv
from sklearn.linear_model import Ridge, Lasso, ElasticNetCV
from sklearn.model_selection import GridSearchCV, KFold
import numpy as np
import pandas as pd

'''

def lasso(x_train, y_train, x_test):
    param_grid = {'alpha': [5]}  # , 0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1,0.0005
    model = GridSearchCV(Lasso(), param_grid, cv=10).fit(x_train, y_train)
    y_pred = model.predict(x_test)
    print(y_pred)
    return y_pred


# @data.route('/trainData')# @data.route('/yuce')
# def train(X, Y,x_1, fold, model_type):


def Kflodtrain(X, Y, x_1, fold, model_type):
    kfold = KFold(n_splits=fold, shuffle=True)
    y_test_total, y_pred_total = [], []
    for train_index, test_index in kfold.split(X, Y):
        x_train, y_train = X[train_index], Y[train_index]
        x_test = x_1
        if model_type == "LASSO":
            y_pred_total.append(lasso(x_train, y_train, x_test))
            print(len(x_test))

    y_pred_total = np.concatenate(y_pred_total, axis=0)
    return y_test_total, y_pred_total
'''


def main():
    money = np.array(pd.read_csv("yuce.csv", header=0).values)
    money_1 = np.array(pd.read_csv("yuce_test.csv").values)
    x = money[:, :9]
    y = money[:, 9]
    x_1 = money_1[:1, :9]
    fold = 10
    yucezhi = []
    for i in range(10):
        # print("i=", i, " start")
        # y_test_total, y_pred_total = Kflodtrain(x, y,x_1 ,fold, "LASSO")
        kfold = KFold(n_splits=fold, shuffle=True)
        y_test_total, y_pred_total = [], []
        for train_index, test_index in kfold.split(x, y):
            x_train, y_train = x[train_index], y[train_index]
            x_test = x_1
            param_grid = {'alpha': [5]}  # , 0.001, 0.005, 0.01, 0.05, 0.1, 0.5, 1,0.0005
            model = GridSearchCV(Lasso(), param_grid, cv=10).fit(x_train, y_train)
            y_pred = model.predict(x_test)
            yucezhi.append(y_pred)
    a=np.array(yucezhi)
    m=a.mean()
    return int(m)


if __name__ == "__main__":
    print(main())
